package com.falcon.core.utils;

import com.falcon.core.enums.ResponseCodeEnum;
import com.falcon.core.exception.BaseException;

/**
 * @author zongf
 * @date 2024-02-08
 **/
public class AssertUtil {


    public static void throwException(int code, String message) {
        throw new BaseException(code, message);
    }

    public static void throwException(ResponseCodeEnum errorCode, String... replaceMessage) {
        if (errorCode == null || replaceMessage.length == 0 ) {
            throw new BaseException(errorCode.getCode(), errorCode.getDescription());
        }else {
            throw new BaseException(errorCode.getCode(), replaceMessage[0]);
        }
    }

    public static void assertNotNull(Object object, ResponseCodeEnum errorCode, String... replaceMessage) {
        if (object == null) {
            throwException(errorCode, replaceMessage);
        }
    }

    public static void asserNotEmpty(Object[] array, ResponseCodeEnum errorCode, String... replaceMessage) {
        if (array == null || array.length == 0) {
            throwException(errorCode, replaceMessage);
        }
    }

    public static void assertTrue(boolean isTrue, ResponseCodeEnum errorCode, String... replaceMessage) {
        if (!isTrue) {
            throwException(errorCode, replaceMessage);
        }
    }

    public static void assertTrue(boolean isTrue, ResponseCodeEnum errorCode, String replaceMessage) {
        if (!isTrue) {
            throwException(errorCode, replaceMessage);
        }
    }

    public static void assertTrue(boolean isTrue, int code, String message) {
        if (!isTrue) {
            throw new BaseException(code, message);
        }
    }

}
